<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Patient Profile Detail</title>
		<link href="../css/default.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jsx.js"></script>
		<script type="text/javascript" src="../js/jsml.js"></script>
		<script type="text/javascript" src="../js/ui.js"></script>
		<script type="text/javascript" src="../js/ris.js"></script>
		<script type="text/javascript" src="../js/SR.js"></script>
		<script type="text/javascript" src="../js/preview.js"></script>
		<script type="text/javascript" src="../js/layout.js"></script>
		<script type="text/javascript" >
			var imagePath = "../images";

			function onBodyLoad()
			{
				if(!Ris)
					return;
					
				Label.setValues({
					labelName: SR.PatientDemographics.Name,
					labelMrn: SR.PatientDemographics.Mrn,
					labelDateOfBirth: SR.PatientDemographics.DateOfBirth,
					labelAge: SR.PatientDemographics.Age,
					labelSex: SR.PatientDemographics.Sex,
					labelHealthcard: SR.PatientDemographics.Healthcard,
					labelBillingInformation: SR.PatientDemographics.BillingInformation,
					labelHomePhone: SR.PatientDemographics.HomePhone,
					labelHomeAddress: SR.PatientDemographics.HomeAddress,
					labelAlerts: SR.PatientDemographics.Alerts,
					labelLanguage: SR.PatientDemographics.Language,
					labelReligion: SR.PatientDemographics.Religion,
					labelAddressType: SR.PatientDemographics.AddressType,
					labelAddress: SR.PatientDemographics.Address,
					labelAddressExpiryDate: SR.PatientDemographics.ExpiryDate,
					labelPhoneType: SR.PatientDemographics.PhoneType,
					labelPhoneNumber: SR.PatientDemographics.PhoneNumber,
					labelPhoneExpiryDate: SR.PatientDemographics.ExpiryDate,
					labelEmailAddress: SR.PatientDemographics.EmailAddress,
					labelEmailExpiryDate: SR.PatientDemographics.ExpiryDate,
					labelContactType: SR.PatientDemographics.ContactType,
					labelContactRelationship: SR.PatientDemographics.ContactRelationship,
					labelContactName: SR.PatientDemographics.ContactName,
					labelContactHomePhone: SR.PatientDemographics.ContactHomePhone,
					labelContactWorkPhone: SR.PatientDemographics.ContactWorkPhone,
					labelContactAddress: SR.PatientDemographics.ContactAddress
				});

				var context = Ris.getHealthcareContext();
				if (context == null)
				{
					Field.setValue($("myForm"), "");
					return;
				}

				Ris.getPatientDataService().getDataAsync(CreateRequest(context), OnPatientDataLoaded);
			}

			function CreateRequest(context)
			{
				return {
					GetPatientProfileDetailRequest: {
						PatientProfileRef: context.PatientProfileRef,
						IncludeAlerts: true,
						IncludeAddresses: true,
						IncludeTelephoneNumbers: true,
						IncludeEmailAddresses: true,
						IncludeContactPersons: true
					}
				};
			}

			function OnPatientDataLoaded(data)
			{
				if (data == null || data.length == 0)
				{
					Field.setValue($("myForm"), "");
					return;
				}

				// update patient demography
				var patientProfile = data.GetPatientProfileDetailResponse.PatientProfile;
				var patientName = Ris.formatPersonName(patientProfile.Name);
				if (patientProfile)
				{
					Field.setValue($("name"), patientName);
					Field.setValue($("mrn"), Ris.formatMrn(patientProfile.Mrn));
					Field.setValue($("age"), Preview.getPatientAge(patientProfile.DateOfBirth, patientProfile.DeathIndicator, patientProfile.TimeOfDeath));
					Field.setValue($("sex"), patientProfile.Sex.Value);	
					Field.setValue($("dateOfBirth"), Ris.formatDate(patientProfile.DateOfBirth));
					Field.setValue($("healthcard"), Ris.formatHealthcard(patientProfile.Healthcard));
					Field.setValue($("billingInformation"), patientProfile.BillingInformation);
					Field.setValue($("currentHomePhone"), Ris.formatTelephone(patientProfile.CurrentHomePhone));
					Field.setValue($("currentHomeAddress"), Ris.formatAddress(patientProfile.CurrentHomeAddress));
					Preview.SectionContainer.create($("PrimaryDemographicsSection"), SR.PatientDemographics.PrimaryDemographics);

					Preview.SectionContainer.create($("CultureSection"), SR.PatientDemographics.Culture);
					if(patientProfile.PrimaryLanguage)
						Field.setValue($("primaryLanguage"), patientProfile.PrimaryLanguage.Value);
					if(patientProfile.Religion)
						Field.setValue($("religion"), patientProfile.Religion.Value);

					Preview.SectionContainer.create($("AddressesSection"), SR.PatientDemographics.Addresses);
					initAddressTable($("addressTable"), patientProfile.Addresses); 

					Preview.SectionContainer.create($("PhoneNumbersSection"), SR.PatientDemographics.PhoneNumbers);
					initPhoneTable($("phoneTable"), patientProfile.TelephoneNumbers); 

					Preview.SectionContainer.create($("EmailAddressesSection"), SR.PatientDemographics.EmailAddresses);
					initEmailTable($("emailTable"), patientProfile.EmailAddresses); 

					Preview.SectionContainer.create($("ContactsSection"), SR.PatientDemographics.Contacts);
					initContactTable($("contactTable"), patientProfile.ContactPersons);
				}

				// update alerts
				var alertNotifications = data.GetPatientProfileDetailResponse.PatientAlerts;
				if (alertNotifications)
					Preview.createAlerts($("alerts"), alertNotifications, patientName);
			}

			function initAddressTable(htmlTable, addresses)
			{
				htmlTable = Table.createTable(htmlTable, { editInPlace: false, flow: false },
					[
						{	label: SR.PatientDemographics.AddressType,
							cellType: "text",
							getValue: function(item) { return item.Type.Value; }
						},
						{	label: SR.PatientDemographics.Address,
							cellType: "text",
							getValue: function(item) { return Ris.formatAddress(item); }
						},
						{	label: SR.PatientDemographics.ExpiryDate,
							cellType: "text",
							getValue: function(item) { return Ris.formatDate(item.ValidRangeUntil); }
						}
					]);
					
				htmlTable.rowCycleClassNames = ["row0", "row1"];
				htmlTable.bindItems(addresses);
			}

			function initPhoneTable(htmlTable, phoneNumbers)
			{
				htmlTable = Table.createTable(htmlTable, { editInPlace: false, flow: false },
					[
						{	label: SR.PatientDemographics.PhoneType,
							cellType: "text",
							getValue: function(item) { return item.Type.Value; }
						},
						{	label: SR.PatientDemographics.PhoneNumber,
							cellType: "text",
							getValue: function(item) { return Ris.formatTelephone(item); }
						},
						{	label: SR.PatientDemographics.ExpiryDate,
							cellType: "text",
							getValue: function(item) { return Ris.formatDate(item.ValidRangeUntil); }
						}
					]);
					
				htmlTable.rowCycleClassNames = ["row0", "row1"];
				htmlTable.bindItems(phoneNumbers);
			}

			function initEmailTable(htmlTable, emails)
			{
				htmlTable = Table.createTable(htmlTable, { editInPlace: false, flow: false },
					[
						{	label: SR.PatientDemographics.EmailAddress,
							cellType: "text",
							getValue: function(item) { return item.Address; }
						},
						{	label: SR.PatientDemographics.ExpiryDate,
							cellType: "text",
							getValue: function(item) { return Ris.formatDate(item.ValidRangeUntil); }
						}
					]);
					
				htmlTable.rowCycleClassNames = ["row0", "row1"];
				htmlTable.bindItems(emails);
			}

			function initContactTable(htmlTable, contacts)
			{
				htmlTable = Table.createTable(htmlTable, { editInPlace: false, flow: false },
					[
						{	label: SR.PatientDemographics.ContactType,
							cellType: "text",
							getValue: function(item) { return item.Type.Value; }
						},
						{	label: SR.PatientDemographics.ContactRelationship,
							cellType: "text",
							getValue: function(item) { return item.Relationship.Value; }
						},
						{	label: SR.PatientDemographics.ContactName,
							cellType: "text",
							getValue: function(item) { return item.Name; }
						},
						{	label: SR.PatientDemographics.ContactHomePhone,
							cellType: "text",
							getValue: function(item) { return Ris.formatStringTelephone(item.HomePhoneNumber); }
						},
						{	label: SR.PatientDemographics.ContactWorkPhone,
							cellType: "text",
							getValue: function(item) { return Ris.formatStringTelephone(item.BusinessPhoneNumber); }
						},
						{	label: SR.PatientDemographics.ContactAddress,
							cellType: "text",
							getValue: function(item) { return item.Address; }
						}
					]);
					
				htmlTable.rowCycleClassNames = ["row0", "row1"];
				htmlTable.bindItems(contacts);
			}
		</script>
	</head>
	<body onload="javascript: onBodyLoad()">
		<form id="myForm">
			<div style="{width:48%; float:left}">
				<div id="PrimaryDemographicsSection">
					<table style="{margin-bottom:2em}">
						<tr>
							<td class="propertyname" id="labelName">Name</td>
							<td colspan="3"><div id="name"/></td>
						</tr>
						<tr>
							<td class="propertyname" id="labelMrn">MRN</td>
							<td colspan="3"><div id="mrn"/></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td width="120" class="propertyname" id="labelDateOfBirth">Date of Birth</td>
							<td width="200"><div id="dateOfBirth"/></td>
							<td width="63" class="propertyname" id="labelAge">Age</td>
							<td width="229"><div id="age"/></td>
						</tr>
						<tr>
							<td width="63" class="propertyname" id="labelSex">Sex</td>
							<td width="229"><div id="sex"/></td>
							<td class="propertyname" id="labelHealthcard">Healthcard # </td>
							<td><div id="healthcard"/></td>
						</tr>
						<tr>
							<td width="63" class="propertyname" id="labelBillingInformation">Billing Information</td>
							<td><div id="billingInformation"/></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td class="propertyname" id="labelHomePhone">Home Phone</td>
							<td colspan="3"><div id="currentHomePhone"/></td>
						</tr>
						<tr>
							<td class="propertyname" id="labelHomeAddress">Home Address</td>
							<td colspan="3"><div id="currentHomeAddress"/></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td class="propertyname" id="labelAlerts">Alerts</td>
							<td rowspan="3"><div id="alerts"/></td>
						</tr>
					</table>
				</div>
				<div id="CultureSection">
					<table style="{margin-bottom:2em}" >
						<tr>
							<td width="120" class="propertyname" id="labelLanguage">Language</td>
							<td><div id="primaryLanguage"/></td>
						</tr>
						<tr>
							<td width="120" class="propertyname" id="labelReligion">Religion</td>
							<td><div id="religion"/></td>
						</tr>
					</table>
				</div>
			</div>
			<div style="{width:48%; float:right}">
				<div id="AddressesSection">
					<table style="{margin-bottom:2em}"  id="addressTable">
						<tr class="tableheading">
							<td width="75" id="labelAddressType">Type</td>
							<td id="labelAddress">Address</td>
							<td width="120" id="labelAddressExpiryDate">Expiry Date</td>
						</tr>
					</table>
				</div>
				<div id="PhoneNumbersSection">
					<table style="{margin-bottom:2em}" id="phoneTable">
						<tr class="tableheading">
							<td width="75" id="labelPhoneType">Type</td>
							<td id="labelPhoneNumber">Phone Number</td>
							<td width="120" id="labelPhoneExpiryDate">Expiry Date</td>
						</tr>
					</table>
				</div>
				<div id="EmailAddressesSection">
					<table style="{margin-bottom:2em}" id="emailTable">
						<tr class="tableheading">
							<td id="labelEmailAddress">Address</td>
							<td width="120" id="labelEmailExpiryDate">Expiry Date</td>
						</tr>
					</table>
				</div>
				<div id="ContactsSection">
					<table style="{margin-bottom:2em}" id="contactTable">
						<tr class="tableheading">
							<td id="labelContactType">Type</td>
							<td id="labelContactRelationship">Relationship</td>
							<td id="labelContactName">Name</td>
							<td id="labelContactHomePhone">Home #</td>
							<td id="labelContactWorkPhone">Work #</td>
							<td id="labelContactAddress">Address</td>
						</tr>
					</table>
				</div>
			</div>
			<div style="{clear:both}"></div>
		</form>
	</body>
</html>
